<!-- #INCLUDE Virtual="/lib.asp" -->
<!-- #INCLUDE Virtual="/lib_gen.asp" -->

<%
dim rss, objXMLDom, objXMLdata
dim rssTitle, rssInhoud
const rssError = "Geen AGENDA data ontvangen"
rssInhoud = rssError

Dim http: Set http = Server.CreateObject("MSXML2.ServerXMLHTTP")

'xmlns:gCal="http://schemas.google.com/gCal/2005" xmlns:gd="http://schemas.google.com/g/2005"

Set objXMLDom = Server.CreateObject("Microsoft.XMLDOM")
objXMLDom.preserveWhiteSpace = true
objXMLDom.async = false
objXMLDom.resolveExternals = false
objXMLDom.setProperty "SelectionNamespaces", "xmlns=""http://www.w3.org/2005/Atom"" xmlns:openSearch=""http://a9.com/-/spec/opensearchrss/1.0/"" xmlns:gCal=""http://schemas.google.com/gCal/2005"" xmlns:gd=""http://schemas.google.com/g/2005"""

on error resume next

'Always specify username/password here, for fail safety
http.open "GET", application("Agenda_Feed"), False,"",""
http.send
rss = http.responseText

objXMLDom.loadXML(rss)
Set objXMLdata = objXMLDom.documentElement

dim node, start, vstart, einde, maand, vmaand, nextRelFound

nextRelFound = false

for each item in objXMLdata.selectNodes("//entry")
	if rssInhoud = rssError then rssInhoud = ""
	
	'<gd:when endTime="2014-04-15" startTime="2014-04-01"/> '2014-04-15T11:00:00.000+02:00
	start = item.selectSingleNode("./gd:when").getAttribute("startTime")
	
	tmparr = split(start, "T") ' 2014-04-15T11:00:00.000+02:00
	startdate = tmparr(0)
	if ubound(tmparr) > 0 then
		starttime = tmparr(1) ' 11:00:00.000+02:00
		tmparr = split(starttime, ".")
		starttime = tmparr(0) ' 11:00:00
		tmparr = split(starttime, ":")
		starttime = tmparr(0) & ":" & tmparr(1)
	else
		starttime = ""
	end if
	
	tmparr = split(startdate, "-") ' YYYY-MM-DD
	maand = cint(tmparr(1))
	
	if maand <> vmaand then
		rssInhoud = rssInhoud & "<div class=""agenda-line agenda-maand not-in-viewport"">" & monthname(maand) & "</div>"
	end if
	
	startday = tmparr(2)
	einde = item.selectSingleNode("./gd:when").getAttribute("endTime")
	rssInhoud = rssInhoud & "<div class=""agenda-line not-in-viewport"">"
	if startday = vstart then
		rssInhoud = rssInhoud & "<span class=""kol1""></span>"
	else
		rssInhoud = rssInhoud & "<span class=""kol1"">" & startday & "</span>"
	end if
	rssInhoud = rssInhoud & "<span class=""kol2"">" & starttime & "</span>"
	rssInhoud = rssInhoud & "<span class=""kol3"">" & item.selectSingleNode("title").text & "</span>"
	rssInhoud = rssInhoud & "</div>"
	
	'rememeber when the next release is planned "naar PROD"
	if instr(item.selectSingleNode("title").text, "naar PROD") > 0 and not nextRelFound then
		ta = split(item.selectSingleNode("title").text, " ")
		application("versions.next.release") = startdate
		application("versions.next.release.number") = ta(0)
		nextRelFound = true 'only remember the first upcoming release
	end if
	
	vstart = startday
	vmaand = maand
next

rssInhoud = "<div id=""container"" style=""height: 400px;"">" & rssInhoud & "</div>" & vbcrlf

rssScript = "<script>" & vbcrlf &_
	"$(document).ready(function() { hideOutsideViewport('.agenda-line') });" & vbcrlf &_
	"</script>" & vbcrlf

call generatePageEx(request("preview"), request.querystring("nextpage"), "Agenda politie.nl", "", "", rssInhoud & rssScript, "../../images/demo.jpg", 30)

%>